package com.example.controller;

import com.example.model.Teacher;
import com.example.service.TeacherService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    private final TeacherService teacherService;

    @Autowired
    public TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @PostMapping("/login")
    public String login(HttpServletResponse response,@RequestParam("number")String number, @RequestParam("password")String teacherPassword) {

            return teacherService.login(response,number, teacherPassword);

    }

    @PostMapping("/register")
    public String register(@RequestBody Teacher teacher) {

        return teacherService.register(teacher);
    }


    @PostMapping("/update")
    public void update(@RequestParam(value = "number")String number,@RequestParam("teacherPassword")String teacherPassword){
        teacherService.update(number,teacherPassword);
        System.out.println(number);
    }

    @PostMapping("/select")
    public Teacher select(@RequestParam("number")String number){
       return teacherService.select(number);
    }
    @PostMapping("/updateAll")
    public void updateAll(@RequestBody Teacher teacher){
        teacherService.updateTeacherInfo(teacher);
    }
}
